/*******************************************************************************
 * Copyright (c) 2013 Michele Nanna.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     https://gitorious.org/provinciawifi - initial API and implementation
 *     Michele Nanna - fix some issues
 ******************************************************************************/
package com.systemfastforward.provinciawifi;


import android.content.Intent;
import android.os.Bundle;

import com.actionbarsherlock.app.SherlockPreferenceActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.systemfastforward.provinciawifi.service.WifiAuthenticatorService;

public class AutoLoginServicePreferenceActivity extends SherlockPreferenceActivity {

    @SuppressWarnings("deprecation")
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        
        // using deprecation for compatibility issues
        addPreferencesFromResource(R.xml.auto_login_preferences);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);

        MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.menu.prefs_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.retry_login:
            retryLogin();
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

    private void retryLogin() {
        startService(new Intent(this, WifiAuthenticatorService.class));
    }
}
